package com.imnc.foodmap.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.baidu.mapapi.search.MKPoiInfo;
import com.imnc.foodmap.R;
import com.imnc.foodmap.ui.adapter.base.NormalListAdapter;

public class SearchResultAdapter extends NormalListAdapter<MKPoiInfo> {

	private LayoutInflater mInflater = null;

	public SearchResultAdapter(Context context) {
		super();
		mInflater = LayoutInflater.from(context);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		ViewHolder viewHolder = null;

		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.listitem_search_result,
					null);
			viewHolder = new ViewHolder();

			viewHolder.name = (TextView) convertView
					.findViewById(R.id.txt_name);
			viewHolder.address = (TextView) convertView
					.findViewById(R.id.txt_address);

			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}

		MKPoiInfo info = itemContent.get(position);

		viewHolder.name.setText((position + 1) + "." + info.name);
		viewHolder.address.setText(info.address);

		return convertView;
	}

	private static class ViewHolder {
		TextView name;
		TextView address;
	}
}
